package cn.edu.ujn.lab.service;

import cn.edu.ujn.lab.dao.Notice;
import cn.edu.ujn.lab.dao.NoticeMapper;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
@Service
@Transactional
public class NoticeServiceImpl implements INoticeService{

    @Autowired
    private NoticeMapper noticeDao;

    @Override
    public Notice findById(Integer id) {
        return noticeDao.selectByPrimaryKey(id);
    }

    @Override
    public Notice insert(Notice notice) {
        int insert = noticeDao.insert(notice);
        return notice;
    }

    @Override
    public List<Notice> findAll() {
        return noticeDao.findAll();
    }

    @Override
    public Integer delete(Integer id) {
        return noticeDao.deleteByPrimaryKey(id);
    }

    @Override
    public Notice update(Notice notice) {
        int i = noticeDao.updateByPrimaryKeySelective(notice);
        return notice;
    }

    @Override
    public Page<Notice> selectAll(Notice notice) {
        List<Notice> list = noticeDao.selectAll(notice);
        Page<Notice> page = new Page<Notice>();
        page.setSize(notice.getRows());
        page.setRows(list);
        page.setPage(notice.getStart());
        page.setTotal(noticeDao.selectCount());
        return page;
    }

}
